#! /usr/bin/env python
# -*- coding: utf-8 -*-

# *************************************************************
#     Filename @  binary_search.py
#       Author @  Huoty
#  Create date @  2016-06-14 16:12:18
#  Description @  
# *************************************************************

import collections
import random as py_random
import timeit

import numpy.random as np_random
import pandas as pd

DATA_SIZE = 10000000

def py_cal_len():
    data = [py_random.randint(0, 1000) for _ in xrange(DATA_SIZE)]
    len(set(data))

def pd_cal_len():
    data = np_random.randint(1000, size=DATA_SIZE)
    data = pd.Series(data)
    data_unique = data.value_counts()
    data_unique.size

def py_count():
    data = [py_random.randint(0, 1000) for _ in xrange(DATA_SIZE)]
    collections.Counter(data)

def pd_count():
    data = np_random.randint(1000, size=DATA_SIZE)
    data = pd.Series(data)
    data.value_counts()

# Script starts from here

if __name__ == "__main__":
    t1 = timeit.Timer("py_cal_len()", setup="from __main__ import py_cal_len")
    t2 = timeit.Timer("pd_cal_len()", setup="from __main__ import pd_cal_len")
    t3 = timeit.Timer("py_count()", setup="from __main__ import py_count")
    t4 = timeit.Timer("pd_count()", setup="from __main__ import pd_count")

    print t1.timeit(number=1)
    print t2.timeit(number=1)
    print t3.timeit(number=1)
    print t4.timeit(number=1)

